Skip to content

Validate sprint7 solver input bounds - #80

Closed
krotname wants to merge 1 commit into
mainfrom
codex/fix-unbounded-stdin-issues-in-sprint7
Closed

Validate sprint7 solver input bounds#80
krotname wants to merge 1 commit into
mainfrom
codex/fix-unbounded-stdin-issues-in-sprint7

Conversation

@krotname

Copy link
Copy Markdown
Owner

Motivation

  • The sprint7 solvers trusted untrusted stdin sizes and contents, allowing negative or huge n to trigger NegativeArraySizeException/OutOfMemoryError and permitting integer overflow when accumulating point totals.
  • The Levenshtein solver buffered unbounded lines and does O(n*m) work with no input-size guard, enabling memory or CPU exhaustion on oversized inputs.

Description

  • Added MAX_GAMES and MAX_TOTAL limits and validated points.length and each point before use in EqualSums, and changed the accumulator to a long to avoid overflow when computing the bitmap target (then cast to int).
  • Added checks in EqualSums.run() to validate n and per-point values read from stdin to avoid negative sizes or oversized allocations.
  • Added MAX_LINE_LENGTH and pre-checks in LevenshteinDistance.solve() and changed FastIn.nextLine() to nextLine(int maxLength) which enforces a maximum line length and caps buffer growth to prevent unbounded buffering.
  • Updated CLI usage to call the bounded nextLine(MAX_LINE_LENGTH) for both input lines in LevenshteinDistance.

Testing

  • Ran mvn test and the full test suite completed successfully after the changes.
  • Compiled the modified classes with javac -d /tmp/ckj_classes src/main/java/algorithms/sprint7/EqualSums.java src/main/java/algorithms/sprint7/LevenshteinDistance.java and exercised them via the CLI to confirm expected behavior for normal inputs.
  • Verified unsafe cases produce graceful errors instead of JVM crashes: negative n or overly large n/point totals in EqualSums return an IO/argument error rather than NegativeArraySizeException/OutOfMemoryError, and overly long lines to LevenshteinDistance produce an Input line is too long error instead of unbounded OOM or excessive CPU.
  • Performed quick smoke checks that the solvers still return correct results on representative valid inputs (examples executed via java -cp /tmp/ckj_classes algorithms.sprint7.EqualSums and algorithms.sprint7.LevenshteinDistance).

Codex Task

@codecov

codecov Bot commented Jul 31, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 36.84211% with 12 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
src/main/java/algorithms/sprint7/EqualSums.java 33.33% 5 Missing and 5 partials ⚠️
...n/java/algorithms/sprint7/LevenshteinDistance.java 50.00% 1 Missing and 1 partial ⚠️

📢 Thoughts on this report? Let us know!

@sonarqubecloud

Copy link
Copy Markdown

Quality Gate Failed Quality Gate failed

Failed conditions
65.9% Coverage on New Code (required ≥ 80%)

See analysis details on SonarQube Cloud

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 692189eefb

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/main/java/algorithms/sprint7/LevenshteinDistance.java
@krotname

krotname commented Aug 1, 2026

Copy link
Copy Markdown
Owner Author

Закрываю как superseded by #116: изменения перенесены в одну проверенную ветку, все review findings учтены; локальный mvn verify прошёл полностью.

@krotname krotname closed this Aug 1, 2026
@krotname
krotname deleted the codex/fix-unbounded-stdin-issues-in-sprint7 branch August 1, 2026 08:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant